	$(document).ready(function() {
	    let tr = $(".section-body");
	    let userId = $(".userid").val(); // 当前用户ID
	    let targetid = $(".sellerid").val();// 商家ID 
	    tr.empty();
	    $.ajax({
	        url: "/poj-java/selectAllUserComents",
	        type: "GET",
	        data: {
	            target_user_id: targetid,
	            current_user_id: userId 
	        },
	        success: function(data) {
	            console.log(data);
	            let allData = data.data;
	            let length = allData.length;
	            for (var i = 0; i < length; i++) {
	                let everyRow = allData[i];
	                // 根据投票状态设置按钮样式
	                let likeClass = everyRow.voteType === 1 ? 'fas' : 'far';
	                let likeStyle = everyRow.voteType === 1 ? 'color:red;' : '';
	                
	                let dislikeClass = everyRow.voteType === -1 ? 'fas' : 'far';
	                let dislikeStyle = everyRow.voteType === -1 ? 'color:black;' : '';
	                
	                let td = `<ul>
	                    <li>
	                        <input type="hidden" value="${everyRow.commentId}" class="commentId">
	                        <img src="${everyRow.headimg}" style="width:40px;border-radius: 50%;">
	                        <span>${everyRow.username}</span>
	                    </li>
	                    <li>
	                        ${everyRow.content}
	                    </li>
	                    <li>
	                        ${everyRow.created_at}
	                    </li>
	                    <li class="recive_left">
	                        <span>评分:${everyRow.score}</span>
	                    </li>
	                    <li class="recive_left">
	                        <span class="likeButton">
	                            <i class="${likeClass} fa-thumbs-up upIdear" style="${likeStyle}">
	                                <input type="hidden" value="1">
	                            </i>点赞
	                        </span>
	                        <span></span>
	                        <span class="dislikeButton">
	                            <i class="${dislikeClass} fa-thumbs-down downIdear" style="${dislikeStyle}">
	                                <input type="hidden" value="-1">
	                            </i>踩
	                        </span>
	                        <span></span>
	                    </li>
	                </ul>`;
	                tr.append(td);
	            };
	        }
	    });
	});

	// 投票按钮点击事件
	$(document).on('click', '.likeButton, .dislikeButton', function() {
	    let $button = $(this);
	    let $commentItem = $button.closest('ul');
	    let commentId = $commentItem.find('.commentId').val();
	    let voteType = $button.find('input').val();
	    let userId = $('.userid').val(); // 当前用户ID
	    
	    $.ajax({
	        url: "/poj-java/AddUserComents",
	        type: "GET",
	        data: {
	            commentId: commentId,
	            targetid: userId, // 商家ID
	            userId: userId,   // 当前用户ID
	            voteType: voteType
	        },
	        success: function(data) {
	            console.log("投票结果:", data);
	            if(data.code === 200) {
	                // 获取返回的投票状态
	                let voteType = data.data.voteType;
	                
	                // 重置所有按钮样式
	                $button.closest('ul').find('.fa-thumbs-up').removeClass('fas').addClass('far').css('color', '');
	                $button.closest('ul').find('.fa-thumbs-down').removeClass('fas').addClass('far').css('color', '');
	                
	                // 根据投票状态更新样式
	                if(voteType === 1) {
	                    $button.closest('ul').find('.fa-thumbs-up').removeClass('far').addClass('fas').css('color', 'red');
	                } else if(voteType === -1) {
	                    $button.closest('ul').find('.fa-thumbs-down').removeClass('far').addClass('fas').css('color', 'black');
	                }
	            }
	        }
	    });
	});
	$("#send-conment").click(function(){
		let sellerid = $(".sellerid").val();
		let userid = $(".userid").val();
		let myComent = $(".myComent").val();
		let myScore = $(".myScore").val();
		console.log(myComent+"****"+myScore);
		$.ajax({
			url:"AddUserComents",
			type:"POST",
			data:{
				sellerid:sellerid,
				userid:userid,
				myComent:myComent,
				myScore:myScore
			},
			success:function(data){
				console.log(data);
			}
		})
	});
